package gov.sat.tax.fwsk.wlrz;

import gov.chinatax.skskj.tools.CreateXmlBean;
import gov.sat.tax.fwsk.common.ConnectionPoolBean;
import gov.sat.tax.fwsk.rz.GSRzFpdklMxDataBean;
import gov.sat.tax.fwsk.rz.WsrzQyUserManageCmdBean;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WlrzJmjControlServletLn extends HttpServlet {
	private static final long serialVersionUID = 1769719999565272628L;
	private static JmjPoolCycle pool;
	private static String welcomeMsg = "";

	public int compDate(String inDate) {
		GregorianCalendar curDate = null;
		GregorianCalendar validDate = null;
		int inYear = Integer.parseInt(inDate.substring(0, 4));
		int inMonth = Integer.parseInt(inDate.substring(5, 7));
		int inDay = Integer.parseInt(inDate.substring(8, 10));

		validDate = new GregorianCalendar(inYear, inMonth - 1, inDay);
		validDate.add(6, 1);
		curDate = new GregorianCalendar();
		if (curDate.before(validDate)) {
			curDate.add(5, 15);
			return curDate.after(validDate) ? 0 : 1;
		}
		return -1;
	}

	public String getRdDate(Connection con, String nsr) throws SQLException {
		PreparedStatement stmt = null;
		String sqls = "";
		String rds = "no";
		try {
			if (con == null) {
				System.out.println("[WARN] 开票日期和认定日期比较数据库连接错");
				return "error";
			}
			sqls = " select to_char(pz_rq,'yyyy-mm-dd') as rzdate from htjs.ht_ybnsr_dab where nsrsbh='"
					+ nsr + "' and YXBZ='N' ";

			stmt = con.prepareStatement(sqls);
			ResultSet rs = stmt.executeQuery();
			while (rs.next()) {
				rds = rs.getString("rzdate");
			}
			rs = null;
		} catch (SQLException e) {
			System.out.println("[WARN] 取认定日期出现异常：" + e.toString());
			return "error";
		} finally {
			if (stmt != null) {
				stmt.close();
			}
		}
		if (stmt != null) {
			stmt.close();
		}
		return rds;
	}

	public void dispMessage(HttpServletResponse res, String err_no,
			String title, String rzsj, String czyDm, String czyPwd)
			throws ServletException, IOException {
		res.setContentType("text/html; charset=gb2312");
		PrintWriter out = res.getWriter();
		out.println(err_no);
		out.println(title);
		out.println(rzsj);
		out.println("CZYDM:" + czyDm);
		System.out.println("[INFO]返回数据:" + err_no);
	}

	public void dispMessage1(HttpServletResponse res, String title)
			throws ServletException, IOException {
		res.setContentType("text/html; charset=gb2312");
		PrintWriter out = res.getWriter();

		out.println(title);
	}

	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		pool = JmjPoolCycle.createInstance();
		WlrzConst.init();

		BufferedReader fi = null;
		try {
			String line = null;
			fi = new BufferedReader(new InputStreamReader(getClass()
					.getResourceAsStream("/welcome.txt")));
			while ((line = fi.readLine()) != null) {
				welcomeMsg = welcomeMsg + line
						+ System.getProperty("line.separator");
			}
		} catch (IOException e) {
			System.out.println("[WARN] welcome.txt 不存在!客户端登录提示信息为空");
			if (fi != null) {
				try {
					fi.close();
				} catch (IOException localIOException1) {
				}
			}
		} finally {
			if (fi != null) {
				try {
					fi.close();
				} catch (IOException localIOException2) {
				}
			}
		}
	}

	
	////转换字符串为可打印的非转码字符串
	private String TransQuotePrintable(String mw) {
		byte[] byteCode = (byte[]) null;
		int count = 0;

		String tem = "";
		String tems = "";
		String srent = "";
		count = mw.length();
		byteCode = new byte[1];
		int j = 0;
		for (int i = 0; i < count;) {
			tem = mw.substring(i, i + 1);
			if (tem.equals("%")) {
				tems = mw.substring(i + 1, i + 3);
				i += 3;
				byteCode[0] = Integer.valueOf(tems, 16).byteValue();
				String str = new String(byteCode);
				srent = srent + str;
				j++;
			} else {
				i++;
				tems = tem;
				srent = srent + tems;
			}
		}
		return srent;
	}

	public void dispWelcomeMessage(HttpServletResponse res, String err_no,
			String title, String rzsj, String validDate)
			throws ServletException, IOException {
		res.setContentType("text/html; charset=gb2312");
		PrintWriter out = res.getWriter();
		out.println(err_no);
		out.println(title);
		out.println(rzsj);
		out.println(validDate);
		out.println();
		if (!welcomeMsg.equals("")) {
			out.println(welcomeMsg);
		}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		performTask(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		performTask(request, response);
	}

	public String getCurDateTime() {
		java.sql.Date dt = new java.sql.Date(System.currentTimeMillis());
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String rz_sjstr = sdf.format(dt);
		return rz_sjstr;
	}

	public String getServletInfo() {
		return super.getServletInfo();
	}

	private InFpDataBean makeFpDataBeanHy(TransRzParaBean rq) throws Exception {
		InFpDataBean tmpFpBean = new InFpDataBean();
		String in_Fpdm = "";
		String in_Fphm = "";
		String in_Kpsj = "";
		String in_GfTax = "";
		String in_XfTax = "";
		String in_Fpje = "0";
		String in_Fpse = "0";
		String fpmw = "";
		String in_Fpsl = "";
		String in_Year = "2000";
		String in_Month = "01";
		String in_Day = "01";

		double fpje = 0.0D;
		double fpse = 0.0D;

		String mw1 = rq.getParameter("miwen1") == null ? "" : rq
				.getParameter("miwen1");
		String mw2 = rq.getParameter("miwen2") == null ? "" : rq
				.getParameter("miwen2");
		String mw3 = rq.getParameter("miwen3") == null ? "" : rq
				.getParameter("miwen3");
		String mw4 = rq.getParameter("miwen4") == null ? "" : rq
				.getParameter("miwen4");

		boolean hzfw = "hzfw".equals(rq.getParameter("action"));
		if (hzfw) {
			fpmw = mw1;

			tmpFpBean.setHzInfoList(getInHzInfoList(rq.getParameter("nsrsbh"),
					mw2, mw3, mw4));
		} else {
			fpmw = mw1 + mw2 + mw3 + mw4;
			mw2 = "";
			mw3 = "";
			mw4 = "";
		}
		tmpFpBean.setQd_bz(hzfw ? "Y" : "N");

		fpmw = TransQuotePrintable(fpmw);

		in_Year = rq.getParameter("kpyear") == null ? "2001" : rq
				.getParameter("kpyear");
		in_Month = rq.getParameter("kpmonth") == null ? "01" : rq
				.getParameter("kpmonth");
		in_Day = rq.getParameter("kpday") == null ? "01" : rq
				.getParameter("kpday");
		in_Kpsj = in_Year.substring(2) + in_Month + in_Day;

		in_Fpdm = rq.getParameter("fpdm") == null ? "" : rq
				.getParameter("fpdm");
		in_Fphm = rq.getParameter("fphm") == null ? "" : rq
				.getParameter("fphm");
		in_GfTax = rq.getParameter("gsbh") == null ? "" : rq
				.getParameter("gsbh");
		in_XfTax = rq.getParameter("xsbh") == null ? "" : rq
				.getParameter("xsbh");
		in_Fpje = rq.getParameter("jine") == null ? "0" : rq
				.getParameter("jine");
		in_Fpse = rq.getParameter("shuie") == null ? "0" : rq
				.getParameter("shuie");
		in_Fpsl = "17";

		String tmpnsh = rq.getParameter("nsrsbh") == null ? "" : rq
				.getParameter("nsrsbh");
		try {
			fpje = Double.parseDouble(in_Fpje);
			fpse = Double.parseDouble(in_Fpse);
		} catch (Exception e) {
			fpje = 0.0D;
			fpse = 0.0D;
			System.out.println("[WARN] 提交的金额、税额数据非法, 请检查: " + in_Fpje + ", "
					+ in_Fpse);
		}
		tmpFpBean.setRz_nsrsbh(tmpnsh);
		tmpFpBean.setGf_nsrsbh(in_GfTax);
		tmpFpBean.setXf_nsrsbh(in_XfTax);
		tmpFpBean.setFp_dm(in_Fpdm);
		tmpFpBean.setFp_hm(in_Fphm);
		tmpFpBean.setKprq(in_Kpsj);
		tmpFpBean.setFp_je(fpje);
		tmpFpBean.setFp_se(fpse);
		tmpFpBean.setFp_sl(in_Fpsl);
		tmpFpBean.setFpmw(fpmw);
		return tmpFpBean;
	}

	private InFpDataBean makeFpDataBean(TranslateParaCmdBean rq)
			throws Exception {
		InFpDataBean tmpFpBean = new InFpDataBean();
		String in_Fpdm = "";
		String in_Fphm = "";
		String in_Kpsj = "";
		String in_GfTax = "";
		String in_XfTax = "";
		String in_Fpje = "0";
		String in_Fpse = "0";
		String fpmw = "";
		String in_Fpsl = "";
		String in_Year = "2000";
		String in_Month = "01";
		String in_Day = "01";

		double fpje = 0.0D;
		double fpse = 0.0D;

		String mw1 = rq.getParameter("miwen1") == null ? "" : rq
				.getParameter("miwen1");
		String mw2 = rq.getParameter("miwen2") == null ? "" : rq
				.getParameter("miwen2");
		String mw3 = rq.getParameter("miwen3") == null ? "" : rq
				.getParameter("miwen3");
		String mw4 = rq.getParameter("miwen4") == null ? "" : rq
				.getParameter("miwen4");

		boolean hzfw = "hzfw".equals(rq.getParameter("action"));
		if (hzfw) {
			fpmw = mw1;

			tmpFpBean.setHzInfoList(getInHzInfoList(rq.getParameter("nsrsbh"),
					mw2, mw3, mw4));
		} else {
			fpmw = mw1 + mw2 + mw3 + mw4;
			mw2 = "";
			mw3 = "";
			mw4 = "";
		}
		tmpFpBean.setQd_bz(hzfw ? "Y" : "N");

		fpmw = TransQuotePrintable(fpmw);

		in_Year = rq.getParameter("kpyear") == null ? "2001" : rq
				.getParameter("kpyear");
		in_Month = rq.getParameter("kpmonth") == null ? "01" : rq
				.getParameter("kpmonth");
		in_Day = rq.getParameter("kpday") == null ? "01" : rq
				.getParameter("kpday");
		in_Kpsj = in_Year.substring(2) + in_Month + in_Day;

		in_Fpdm = rq.getParameter("fpdm") == null ? "" : rq
				.getParameter("fpdm");
		in_Fphm = rq.getParameter("fphm") == null ? "" : rq
				.getParameter("fphm");
		in_GfTax = rq.getParameter("gsbh") == null ? "" : rq
				.getParameter("gsbh");
		in_XfTax = rq.getParameter("xsbh") == null ? "" : rq
				.getParameter("xsbh");
		in_Fpje = rq.getParameter("jine") == null ? "0" : rq
				.getParameter("jine");
		in_Fpse = rq.getParameter("shuie") == null ? "0" : rq
				.getParameter("shuie");
		in_Fpsl = "17";

		String tmpnsh = rq.getParameter("nsrsbh") == null ? "" : rq
				.getParameter("nsrsbh");
		try {
			fpje = Double.parseDouble(in_Fpje);
			fpse = Double.parseDouble(in_Fpse);
		} catch (Exception e) {
			fpje = 0.0D;
			fpse = 0.0D;
			if (WlrzConst.isDebug()) {
				System.out.println("[WARN] 提交的金额、税额数据非法, 请检查: " + in_Fpje
						+ ", " + in_Fpse);
			}
		}
		tmpFpBean.setRz_nsrsbh(tmpnsh);
		tmpFpBean.setGf_nsrsbh(in_GfTax);
		tmpFpBean.setXf_nsrsbh(in_XfTax);
		tmpFpBean.setFp_dm(in_Fpdm);
		tmpFpBean.setFp_hm(in_Fphm);
		tmpFpBean.setKprq(in_Kpsj);
		tmpFpBean.setFp_je(fpje);
		tmpFpBean.setFp_se(fpse);
		tmpFpBean.setFp_sl(in_Fpsl);
		tmpFpBean.setFpmw(fpmw);

		return tmpFpBean;
	}

	private InFpDataBean makeFpDataBean(HttpServletRequest rq) throws Exception {
		InFpDataBean tmpFpBean = new InFpDataBean();
		String in_Fpdm = "";
		String in_Fphm = "";
		String in_Kpsj = "";
		String in_GfTax = "";
		String in_XfTax = "";
		String in_Fpje = "0";
		String in_Fpse = "0";
		String fpmw = "";
		String in_Fpsl = "";
		String in_Year = "2000";
		String in_Month = "01";
		String in_Day = "01";

		double fpje = 0.0D;
		double fpse = 0.0D;

		String mw1 = rq.getParameter("miwen1") == null ? "" : rq
				.getParameter("miwen1");
		String mw2 = rq.getParameter("miwen2") == null ? "" : rq
				.getParameter("miwen2");
		String mw3 = rq.getParameter("miwen3") == null ? "" : rq
				.getParameter("miwen3");
		String mw4 = rq.getParameter("miwen4") == null ? "" : rq
				.getParameter("miwen4");

		boolean hzfw = "hzfw".equals(rq.getParameter("action"));
		if (hzfw) {
			fpmw = mw1;

			tmpFpBean.setHzInfoList(getInHzInfoList(rq.getParameter("nsrsbh"),
					mw2, mw3, mw4));
		} else {
			fpmw = mw1 + mw2 + mw3 + mw4;
			mw2 = "";
			mw3 = "";
			mw4 = "";
		}
		tmpFpBean.setQd_bz(hzfw ? "Y" : "N");

		fpmw = TransQuotePrintable(fpmw);

		in_Year = rq.getParameter("kpyear") == null ? "2001" : rq
				.getParameter("kpyear");
		in_Month = rq.getParameter("kpmonth") == null ? "01" : rq
				.getParameter("kpmonth");
		in_Day = rq.getParameter("kpday") == null ? "01" : rq
				.getParameter("kpday");
		in_Kpsj = in_Year.substring(2) + in_Month + in_Day;

		in_Fpdm = rq.getParameter("fpdm") == null ? "" : rq
				.getParameter("fpdm");
		in_Fphm = rq.getParameter("fphm") == null ? "" : rq
				.getParameter("fphm");
		in_GfTax = rq.getParameter("gsbh") == null ? "" : rq
				.getParameter("gsbh");
		in_XfTax = rq.getParameter("xsbh") == null ? "" : rq
				.getParameter("xsbh");
		in_Fpje = rq.getParameter("jine") == null ? "0" : rq
				.getParameter("jine");
		in_Fpse = rq.getParameter("shuie") == null ? "0" : rq
				.getParameter("shuie");
		in_Fpsl = "17";

		String tmpnsh = rq.getParameter("nsrsbh") == null ? "" : rq
				.getParameter("nsrsbh");
		try {
			fpje = Double.parseDouble(in_Fpje);
			fpse = Double.parseDouble(in_Fpse);
		} catch (Exception e) {
			fpje = 0.0D;
			fpse = 0.0D;
			if (WlrzConst.isDebug()) {
				System.out.println("[WARN] 提交的金额、税额数据非法, 请检查: " + in_Fpje
						+ ", " + in_Fpse);
			}
		}
		tmpFpBean.setRz_nsrsbh(tmpnsh);
		tmpFpBean.setGf_nsrsbh(in_GfTax);
		tmpFpBean.setXf_nsrsbh(in_XfTax);
		tmpFpBean.setFp_dm(in_Fpdm);
		tmpFpBean.setFp_hm(in_Fphm);
		tmpFpBean.setKprq(in_Kpsj);
		tmpFpBean.setFp_je(fpje);
		tmpFpBean.setFp_se(fpse);
		tmpFpBean.setFp_sl(in_Fpsl);
		tmpFpBean.setFpmw(fpmw);

		return tmpFpBean;
	}

	public void performTask(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String tmp3 = request.getQueryString();
		String tmp1 = request.getParameter("fpdm");
		System.out.println(tmp1);
		String tmp2 = request.getParameter("fphm");
		System.out.println(tmp2);
		String action = null;
		boolean security = true;
		boolean b_action = false;
		String swjg_dm = "";
		String nsrsbh = "";
		String czyDm = "";
		String czyMc = "";
		String czyPwd = "";

		InFpDataBean inFpData = null;
		JmFpDataBean jmFpData = null;
		long ulms = System.currentTimeMillis();
		boolean hytrans = false;
		boolean szflag = false;
		boolean limitusr = false;
		boolean hzfw = false;
		String rsj = null;
		String fpzl = "YB";
		String gdenable = "N";
		String fjenable = "N";

		boolean isNewClient = false;

		String gdzc = "";

		TransRzParaBean ts = null;

		String data = request.getParameter("ENCODE");
		String rzdata = request.getParameter("RZDATA");
		String isJM = request.getParameter("isJM");
		
		//只是通过解密机mw,dm,hm
		if ("true".equals(isJM)) {
			String rtn = JMSvr(request);
			response.setContentType("text/html; charset=gb2312");
			PrintWriter out = response.getWriter();
			out.println(rtn);
			return;
		}
		if ((rzdata == null) && (data == null)) {
			hytrans = false;
			security = false;
			action = request.getParameter("action");
			szflag = true;
			System.out.println("未加密版本");
		} else if (rzdata != null) {
			hytrans = true;
			security = false;
			szflag = false;
			if (rzdata.startsWith("HY")) {
				rzdata = rzdata.substring(2);
				ts = new TransRzParaBean("");
			} else if (rzdata.length() > 580) {
				ts = new TransRzParaBean(88);
			} else {
				ts = new TransRzParaBean();
			}
			ts.doDecrypt(rzdata);
			if ("hzfw".equals(ts.getParameter("action"))) {
				hzfw = true;
			}
		}
		if ((data == null) || (data.length() <= 56)) {
			action = request.getParameter("action");
		}
		TranslateParaCmdBean parb = new TranslateParaCmdBean();//解密过程
		if (security) {
			parb.doDecrypt(data.trim());

			String newClient = parb.getParameter("newclient");
			if ((newClient != null) && ("true".equals(newClient))) {
				isNewClient = true;
			}
			action = parb.getParameter("action");

			String userCmd = parb.getParameter("cmd") == null ? "n" : parb
					.getParameter("cmd");

			String cxfs = parb.getParameter("cxfs") == null ? "null" : parb
					.getParameter("cxfs").trim();
			String rz_nsrsbh = parb.getParameter("nsrsbh") == null ? "" : parb
					.getParameter("nsrsbh").trim();
			String yf = parb.getParameter("rzyf") == null ? "" : parb
					.getParameter("rzyf").trim();

			String bdate = parb.getParameter("dfrom") == null ? "no" : parb
					.getParameter("dfrom").trim();
			String edate = parb.getParameter("dto") == null ? "no" : parb
					.getParameter("dto").trim();
			if (bdate.length() == 0) {
				bdate = "no";
			}
			if (edate.length() == 0) {
				edate = "no";
			}
			String fplx = parb.getParameter("fplx") == null ? "A" : parb
					.getParameter("fplx");
			gdzc = parb.getParameter("gd") == null ? "A" : parb
					.getParameter("gd");
			if (userCmd.equals("wpmx")) {
				String cxfpdm = parb.getParameter("fpdm") == null ? "" : parb
						.getParameter("fpdm");
				String cxfphm = parb.getParameter("fphm") == null ? "" : parb
						.getParameter("fphm");
				System.out.println("[info] 增值税发票物品明细查询 nsr:" + rz_nsrsbh
						+ " fpdm:" + cxfpdm + " fphm:" + cxfphm);
				if ((cxfpdm.equals("")) || (cxfphm.equals(""))) {
					return;
				}
				String rtnxml = WlrzYcrzcxCmdBean.doQueryXmlWpmx(rz_nsrsbh,
						cxfpdm, cxfphm);
				ServletOutputStream out = null;

				byte[] buf = rtnxml.getBytes();
				out = response.getOutputStream();
				out.write(buf);
				out.flush();
				out.close();
				System.out.println("[info] 明细查询成功返回 ");
				return;
			}
			if (userCmd.equals("mx")) {
				if (WlrzConst.isDebug()) {
					System.out.println("[info] 增值税发票 cxfs: " + cxfs + " nsr: "
							+ rz_nsrsbh + " ssyf: " + yf + " bfrom :" + bdate
							+ " bto " + edate);
				}
				if ((cxfs.equals("21")) || (cxfs.equals("20"))) {
					String rml = WlrzYcrzcxCmdBean.doQueryXmlMx(rz_nsrsbh, yf,
							bdate, edate, cxfs, fplx, gdzc);
					ServletOutputStream out = null;

					byte[] buf = rml.getBytes();
					out = response.getOutputStream();
					out.write(buf);
					out.flush();
					out.close();
					System.out.println("[info] 明细查询成功返回 ");
					return;
				}
			}
			if (userCmd.equals("hz")) {
				System.out.println("[info] hz cxfs: " + cxfs + " nsr: "
						+ rz_nsrsbh + " ssyf: " + yf + " bfrom :" + bdate
						+ " bto " + edate);
				if ((cxfs.equals("20")) || (cxfs.equals("21"))) {
					String rml = WlrzYcrzcxCmdBean.doQueryXmlHz(rz_nsrsbh, yf,
							bdate, edate, cxfs, fplx, gdzc);
					ServletOutputStream out = null;

					byte[] buf = rml.getBytes();
					out = response.getOutputStream();
					out.write(buf);
					out.flush();
					out.close();
					System.out.println("[info] 汇总查询成功返回 ");
					return;
				}
			}
			if (userCmd.equals("kh")) {
				System.out.println("[INFO] ：" + parb.getParameter("nsrsbh"));

				WlrzYcrzcxCmdBean.doQyKh(parb, response);
				return;
			}
			if ((action == null) || (action.length() == 0)) {
				dispMessage(response, "800", "参数错误action为空！", getCurDateTime(),
						czyDm, czyPwd);
				System.out.println("[INFO] 参数错误action为空: " + nsrsbh + ",操作员:"
						+ czyDm + ", 时间:" + getCurDateTime());
				return;
			}
			if (action.equals("rzjgcx")) {
				if (security) {
					WlrzYcrzcxCmdBean.doQuerySjrzSecurity(parb, response);
				}
				return;
			}
			if (action.equals("kh")) {
				WlrzYcrzcxCmdBean.doQyKh(parb, response);
				return;
			}
			if (action.equals("jzrq")) {
				WlrzYcrzcxCmdBean.doChangeJzrq(parb, response);
				return;
			}
			if (action.equals("pwd")) {
				WlrzYcrzcxCmdBean.doUpdatePwd(response, parb);
				return;
			}
			if (action.equals("hzfw")) {
				hzfw = true;
			}
			b_action = action.equals("login");
		}
		if (security) {
			nsrsbh = parb.getParameter("nsrsbh") != null ? parb
					.getParameter("nsrsbh") : "";
			czyDm = parb.getParameter("czydm") != null ? parb
					.getParameter("czydm") : "";
			czyPwd = parb.getParameter("passwd") != null ? parb
					.getParameter("passwd") : "";
		} else if (hytrans) {
			nsrsbh = ts.getParameter("nsrsbh") != null ? ts
					.getParameter("nsrsbh") : "";
			czyDm = "huyou";
			czyPwd = "123456";
		} else if (szflag) {
			nsrsbh = request.getParameter("nsrsbh") != null ? request
					.getParameter("nsrsbh") : "";
			czyDm = "server";
			czyPwd = "123456";
		}
		ConnectionPoolBean handler = null;
		Connection conn = null;
		JmjBean jmj = null;
		label7848: try {
			handler = ConnectionPoolBean.getHandle();
			conn = handler.getConnection();
			if (conn == null) {
				dispMessage(response, "500", "数据库连接错误，不能进行认证操作！",
						getCurDateTime(), czyDm, czyPwd);
				System.out.println("[WARN] 数据库连接错误: " + nsrsbh + ", 操作员:"
						+ czyDm + ", 登录时间:" + getCurDateTime());
				return;
			}
			WsrzQyUserManageCmdBean curCzyDB = new WsrzQyUserManageCmdBean();

			curCzyDB = WsrzQyUserManageCmdBean.doQueryByCzydm(conn, nsrsbh,
					czyDm, czyPwd, WlrzConst.isNeedPwd());
			if (curCzyDB == null) {
				dispMessage(response, "510", "操作员非法，不能进行认证操作！",
						getCurDateTime(), czyDm, czyPwd);
				System.out.println("[WARN] 非法操作员: " + nsrsbh + ", 操作员:" + czyDm
						+ ", 登录时间:" + getCurDateTime());
				return;
			}
			// WsrzQyUserManageCmdBean curCzyDB;
			if ((curCzyDB.getNsrmc() != null)
					&& (curCzyDB.getNsrmc().equals("brkj"))) {
				System.out.println("[INFO] brkjuser " + curCzyDB.getNsrmc());
				limitusr = true;
			}
			czyMc = "服务器";
			swjg_dm = curCzyDB.getSwjg_dm();

			gdenable = curCzyDB.getGdzc_bz();

			int i_validDate = -1;
			i_validDate = compDate(curCzyDB.getJzrq());
			if (i_validDate == -1) {
				dispMessage(response, "525", "用户已超出有效期！", getCurDateTime(),
						czyDm, czyPwd);
				System.out.println("[WARN] 525过期用户: " + nsrsbh + ", 操作员:"
						+ czyDm + ", 登录时间:" + getCurDateTime());
				return;
			}
			// int i_validDate;
			// WsrzQyUserManageCmdBean curCzyDB;
			if (b_action) {
				dispWelcomeMessage(response, "100", "网络认证服务器登录成功！",
						getCurDateTime(), curCzyDB.getJzrq());

				System.out.println("[INFO] 登录成功: " + nsrsbh + ",操作员:" + czyDm
						+ ", 时间:" + getCurDateTime());
				return;
			}
			// int i_validDate;
			// WsrzQyUserManageCmdBean curCzyDB;
			if ((!security) && (!hytrans) && (!szflag)) {
				dispWelcomeMessage(response, "700", "客户端传递参数异常！",
						getCurDateTime(), curCzyDB.getJzrq());
				System.out.println("[INFO] 登录成功: " + nsrsbh + ",操作员:" + czyDm
						+ ", 时间:" + getCurDateTime());
				return;
			}
			// int i_validDate;
			// WsrzQyUserManageCmdBean curCzyDB;
			String fpid = "";
			String fpmw = "";

			String in_Year = "2000";
			String in_Month = "01";
			String in_Day = "01";
			// String in_Day;
			// String in_Month;
			// String in_Year;
			// String fpmw;
			// String fpid;
			if (security) {
				fpid = parb.getParameter("fpid") == null ? "1" : parb
						.getParameter("fpid");

				in_Year = parb.getParameter("kpyear") == null ? "2001" : parb
						.getParameter("kpyear");
				in_Month = parb.getParameter("kpmonth") == null ? "01" : parb
						.getParameter("kpmonth");
				in_Day = parb.getParameter("kpday") == null ? "01" : parb
						.getParameter("kpday");
				String mw1 = parb.getParameter("miwen1") == null ? "" : parb
						.getParameter("miwen1");
				String mw2 = parb.getParameter("miwen2") == null ? "" : parb
						.getParameter("miwen2");
				String mw3 = parb.getParameter("miwen3") == null ? "" : parb
						.getParameter("miwen3");
				String mw4 = parb.getParameter("miwen4") == null ? "" : parb
						.getParameter("miwen4");
				if (hzfw) {
					fpmw = mw1;
				} else {
					fpmw = mw1 + mw2 + mw3 + mw4;
					mw2 = "";
					mw3 = "";
					mw4 = "";
				}
				fpmw = TransQuotePrintable(fpmw);

				String chkprq = in_Year + in_Month + in_Day;
				if (!RzCheckKprqLimit.fpCheckKprqLimit(chkprq, null)) {
					dispMessage(response, "660", "超过抵扣期限的发票,不能进行认证。",
							getCurDateTime(), czyDm, czyPwd);
					System.out.println("[WARN] 超过180天抵扣期限: " + nsrsbh
							+ ", 操作员:" + czyDm + ", 登录时间:" + getCurDateTime());
					return;
				}
				// String chkprq;
				// String mw4;
				// String mw3;
				// String mw2;
				// String mw1;
				// int i_validDate;
				// WsrzQyUserManageCmdBean curCzyDB;
				gdzc = parb.getParameter("gd") == null ? "N" : parb
						.getParameter("gd");
				if (!gdzc.equals("N")) {
					if (gdzc.equals("02")) {
						gdzc = "Y";
					} else if ((gdzc.equals("01")) || (gdzc.equals("00"))) {
						gdzc = "N";
					}
				} else {
					gdzc = "N";
				}
				fjenable = parb.getParameter("fjwz") == null ? "N" : parb
						.getParameter("fjwz");

				inFpData = makeFpDataBean(parb);
			} else if (szflag) {
				in_Year = request.getParameter("kpyear") != null ? request
						.getParameter("kpyear") : "2001";
				in_Month = request.getParameter("kpmonth") != null ? request
						.getParameter("kpmonth") : "01";
				in_Day = request.getParameter("kpday") != null ? request
						.getParameter("kpday") : "01";
				String mw1 = request.getParameter("miwen1") != null ? request
						.getParameter("miwen1") : "";
				String mw2 = request.getParameter("miwen2") != null ? request
						.getParameter("miwen2") : "";
				String mw3 = request.getParameter("miwen3") != null ? request
						.getParameter("miwen3") : "";
				String mw4 = request.getParameter("miwen4") != null ? request
						.getParameter("miwen4") : "";
				if (hzfw) {
					fpmw = mw1;
				} else {
					fpmw = mw1 + mw2 + mw3 + mw4;
					mw2 = "";
					mw3 = "";
					mw4 = "";
				}
				fpmw = TransQuotePrintable(fpmw);
				fpid = request.getParameter("fpid") != null ? request
						.getParameter("fpid") : "1";
				fjenable = "N";
				gdzc = "N";
				inFpData = makeFpDataBean(request);
			} else if (hytrans) {
				fpid = ts.getParameter("fpid");
				in_Year = ts.getParameter("kpyear") == null ? "2001" : ts
						.getParameter("kpyear");
				in_Month = ts.getParameter("kpmonth") == null ? "01" : ts
						.getParameter("kpmonth");
				in_Day = ts.getParameter("kpday") == null ? "01" : ts
						.getParameter("kpday");
				String mw1 = ts.getParameter("miwen1") == null ? "" : ts
						.getParameter("miwen1");
				String mw2 = ts.getParameter("miwen2") == null ? "" : ts
						.getParameter("miwen2");
				String mw3 = ts.getParameter("miwen3") == null ? "" : ts
						.getParameter("miwen3");
				String mw4 = ts.getParameter("miwen4") == null ? "" : ts
						.getParameter("miwen4");
				if (hzfw) {
					fpmw = mw1;
				} else {
					fpmw = mw1 + mw2 + mw3 + mw4;
					mw2 = "";
					mw3 = "";
					mw4 = "";
				}
				fpmw = TransQuotePrintable(fpmw);

				gdzc = ts.getParameter("gdzc");
				if (gdzc != null) {
					if (gdzc.equals("0")) {
						gdzc = "Y";
					} else if (gdzc.equals("1")) {
						gdzc = "N";
					}
				}
				inFpData = makeFpDataBeanHy(ts);
			}
			if ((hzfw)
					&& ((inFpData.getHzInfoList() == null) || (inFpData
							.getHzInfoList().size() == 0))) {
				dispMessage(response, "1000", "物品格式异常！", getCurDateTime(),
						czyDm, czyPwd);
				System.out.println("[ERROR]汉字防伪发票，未上传物品信息 nsr:" + nsrsbh
						+ " fpdm:" + inFpData.getFp_dm() + " fphm:"
						+ inFpData.getFp_hm());
				return;
			}
			// String in_Day;
			// String in_Month;
			// String in_Year;
			// String fpmw;
			// String fpid;
			// int i_validDate;
			// WsrzQyUserManageCmdBean curCzyDB;
			if (!nsrsbh.equals(inFpData.getGf_nsrsbh())) {
				dispMessage(response, "610", "提交纳税人与购方纳税人不符,不能进行网上认证。",
						getCurDateTime(), czyDm, czyPwd);
				System.out.println("[WARN] 购方不符: " + nsrsbh + ", 操作员:" + czyDm
						+ ", 登录时间:" + getCurDateTime());
				return;
			}
			// String in_Day;
			// String in_Month;
			// String in_Year;
			// /String fpmw;
			// String fpid;
			// int i_validDate;
			// WsrzQyUserManageCmdBean curCzyDB;
			int jmStatus = 0;
			String rzSj = "";
			jmFpData = new JmFpDataBean();

			JmHandler curJmHandler = new JmHandler();

			jmj = pool.getJmj();
			String jmjip = "";
			if (jmj != null) {
				jmjip = jmj.getJmjIP();
				if (jmj.isServer()) {
					curJmHandler.doJmProc_Jms(fpmw, jmjip, hzfw);
				} else {
					curJmHandler.doJmProc(nsrsbh, fpmw, fpid, jmjip, hzfw);
				}
				pool.releaseJmj(jmj);
			} else {
				curJmHandler.setStatus(530);
			}
			jmStatus = curJmHandler.getStatus();
			// int jmStatus;
			switch (jmStatus) {
			case 0:
				jmFpData = curJmHandler.getCurJmData();

				int wxyy = 0;
				int rzjg = 0;
				int save_Code = 0;
				int i_err_no = jmFpData.getErrNo();
				// int i_err_no;
				// int rzjg;
				// int wxyy;
				switch (i_err_no) {
				case 0:
				case 1000:
				case 1001:
				case 1002:
					String rddate = getRdDate(conn, nsrsbh);
					if ((rddate.equals("no")) || (rddate.equals("error"))) {
						dispMessage(response, "525", "取得企业认定日期出现异常！",
								getCurDateTime(), czyDm, czyPwd);
						System.out.println("[WARN] 取得企业认定日期出现异常: " + nsrsbh
								+ ", 操作员:" + czyDm + ", 登录时间:"
								+ getCurDateTime());
						return;
					}
					// String rddate;
					// int i_err_no;
					// int save_Code;
					// String jmjip;
					// JmHandler curJmHandler;
					// String rzSj;
					// int jmStatus;
					// String in_Day;
					// String in_Month;
					// String in_Year;
					// String fpmw;
					// String fpid;
					// int i_validDate;
					// WsrzQyUserManageCmdBean curCzyDB;
					java.sql.Date rdDate = java.sql.Date.valueOf(rddate);

					CmpHandler cmpHandler = new CmpHandler();

					cmpHandler.setNewClient(isNewClient);

					cmpHandler.setInData(inFpData);
					cmpHandler.setJmData(jmFpData);

					cmpHandler.setRdDate(rdDate);

					Map map = cmpHandler.doCmpProc();

					inFpData.setIs_Zh(jmFpData.getIs_Zh());
					inFpData.setZhLst(jmFpData.getZhLst());
					inFpData.setHzInfoList(jmFpData.getHzInfoList());

					// int wxyy = cmpHandler.getWxyy();
					// int rzjg = cmpHandler.getRzjg();

					String err_subType = null;
					if ((wxyy == -1) && (rzjg == -5)) {
						dispMessage(response, "670", "取得认定资格前开具的发票。不能进行认证",
								getCurDateTime(), czyDm, czyPwd);
						System.out.println("[WARN] 认定前发票: " + nsrsbh + ", 操作员:"
								+ czyDm + ", 登录时间:" + getCurDateTime());
						return;
					}
					// String err_subType;
					// Map map;
					// CmpHandler cmpHandler;
					// java.sql.Date rdDate;
					// String rddate;
					// int i_err_no;
					// int save_Code;
					// int rzjg;
					// int wxyy;
					// String jmjip;
					// JmHandler curJmHandler;
					// String rzSj;
					// int jmStatus;
					// String in_Day;
					// String in_Month;
					// String in_Year;
					// String fpmw;
					// String fpid;
					// int i_validDate;
					// WsrzQyUserManageCmdBean curCzyDB;
					if ((wxyy == -1) && ((rzjg == -6) || (rzjg == -7))) {
						dispMessage(response, "660", "超过抵扣期限的发票。不能进行认证",
								getCurDateTime(), czyDm, czyPwd);
						System.out.println("[WARN] 超过抵扣期限: " + nsrsbh
								+ ", 操作员:" + czyDm + ", 登录时间:"
								+ getCurDateTime());
						return;
					}
					// String err_subType;
					// Map map;
					// CmpHandler cmpHandler;
					// java.sql.Date rdDate;
					// String rddate;
					// int i_err_no;
					// int save_Code;
					// int rzjg;
					// int wxyy;
					// String jmjip;
					// JmHandler curJmHandler;
					// String rzSj;
					// int jmStatus;
					// String in_Day;
					// String in_Month;
					// String in_Year;
					// String fpmw;
					// String fpid;
					// int i_validDate;
					// WsrzQyUserManageCmdBean curCzyDB;
					inFpData.setFp_sl(jmFpData.getFp_sl());
					if (rzjg == 0) {
						inFpData.setFp_je(jmFpData.getFp_je());
						inFpData.setFp_se(jmFpData.getFp_se());

						inFpData.setHzInfoList(jmFpData.getHzInfoList());
						err_subType = "0";
					} else if ((!inFpData.getFp_dm()
							.equals(jmFpData.getFp_dm()))
							|| (!inFpData.getFp_hm()
									.equals(jmFpData.getFp_hm()))
							|| (!inFpData.getGf_nsrsbh().equals(
									jmFpData.getGf_nsrsbh()))) {
						err_subType = "1";
					} else {
						err_subType = "2";
					}
					// String err_subType;
					// Map map;
					// String rzSj;
					if (rzjg == 0) {
						GSRzFpdklMxDataBean tmpFpDklMxDataBean = new GSRzFpdklMxDataBean();

						tmpFpDklMxDataBean = setRzFpDklMx(inFpData, swjg_dm,
								czyDm, czyMc);

						double se = inFpData.getFp_se();
						String sl = inFpData.getFp_sl();
						// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
						// int save_Code;
						// String rzSj;
						if (jmFpData.getErrNo() == 0) {
							tmpFpDklMxDataBean.setFp_lb("YB");
						} else if ((jmFpData.getErrNo() == 1001)
								|| (se == 0.0D)) {
							System.out.println("[INFO] 属于废旧物资发票");
							tmpFpDklMxDataBean.setFp_lb("FJ");
							fpzl = "FJ";
							if (fjenable.equals("N")) {
								dispMessage(response, "700",
										"当前客户端版本不支持废旧物资发票认证", getCurDateTime(),
										czyDm, czyPwd);
								System.out.println("[WARN] 当前客户端版本不支持废旧物资发票认证:"
										+ nsrsbh + ", 操作员:" + czyDm + ", 认证时间:"
										+ getCurDateTime());
								return;
							}
							// String sl;
							// double se;
							// String err_subType;
							// Map map;
							// CmpHandler cmpHandler;
							// java.sql.Date rdDate;
							// String rddate;
							// int i_err_no;
							// int rzjg;
							// int wxyy;
							// String jmjip;
							// JmHandler curJmHandler;
							// int jmStatus;
							// String in_Day;
							// String in_Month;
							// String in_Year;
							// String fpmw;
							// String fpid;
							// int i_validDate;
							// WsrzQyUserManageCmdBean curCzyDB;
							if (limitusr) {
								dispMessage(response, "700",
										"当前客户端版本不支持废旧物资发票认证", getCurDateTime(),
										czyDm, czyPwd);
								System.out.println("[WARN] 当前客户端版本不支持废旧物资发票认证:"
										+ nsrsbh + ", 操作员:" + czyDm + ", 认证时间:"
										+ getCurDateTime());
								break label7848;
							}
						}
						if (jmFpData.getErrNo() == 1002) {
							System.out.println("[INFO] 属于普通发票");
							if ((szflag) || (limitusr)) {
								dispMessage(response, "700",
										"当前客户端版本不支持普通发票验证", getCurDateTime(),
										czyDm, czyPwd);
								System.out.println("[WARN] 当前客户端版本不支持普通发票验证:"
										+ nsrsbh + ", 操作员:" + czyDm + ", 认证时间:"
										+ getCurDateTime());
								break label7848;
							}
							java.sql.Date rz_sj = null;
							rz_sj = new java.sql.Date(
									System.currentTimeMillis());
							SimpleDateFormat sdf = new SimpleDateFormat(
									"yyyy-MM-dd HH:mm:ss");
							rzSj = sdf.format(rz_sj);

							tmpFpDklMxDataBean.setFp_lb("P1");
							save_Code = tmpFpDklMxDataBean.doInserPvoice(conn);
							fpzl = "P1";
							String r_je = Double.toString(jmFpData.getFp_je());
							String r_se = Double.toString(jmFpData.getFp_se());
							rsj = rzSj + " " + r_je + " " + r_se;
							rzSj = rzSj + " " + r_je + " " + r_se + " "
									+ jmFpData.getFp_dm() + " "
									+ jmFpData.getFp_hm();
							if (save_Code == 1) {
								System.out.println("[INFO] 普票验证通过:" + nsrsbh
										+ ", " + rzSj + "(" + ulms + "ms)");
								dispMessage(response, "1002", "认证相符(普票)", rzSj,
										czyDm, czyPwd);
								return;
							}
							// String r_se;
							// String r_je;
							// SimpleDateFormat sdf;
							// java.sql.Date rz_sj;
							// String sl;
							// double se;
							// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
							// String err_subType;
							// Map map;
							// CmpHandler cmpHandler;
							// java.sql.Date rdDate;
							// String rddate;
							// int i_err_no;
							// int save_Code;
							// int rzjg;
							// int wxyy;
							// String jmjip;
							// JmHandler curJmHandler;
							// String rzSj;
							// int jmStatus;
							// String in_Day;
							// String in_Month;
							// String in_Year;
							// String fpmw;
							// String fpid;
							// int i_validDate;
							// WsrzQyUserManageCmdBean curCzyDB;
							if (save_Code == 2) {
								rzSj = tmpFpDklMxDataBean.getDs_swjg_dm();

								System.out.println("[INFO] 普票重复认证:" + nsrsbh
										+ "," + rzSj + "(" + ulms + "ms)");
								dispMessage(response, "1200", "重复认证(普票)", rzSj,
										czyDm, czyPwd);
								return;
							}
							// String r_se;
							// String r_je;
							// SimpleDateFormat sdf;
							// java.sql.Date rz_sj;
							// String sl;
							// double se;
							// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
							// String err_subType;
							// Map map;
							// CmpHandler cmpHandler;
							// java.sql.Date rdDate;
							// String rddate;
							// int i_err_no;
							// int save_Code;
							// int rzjg;
							// int wxyy;
							// String jmjip;
							// JmHandler curJmHandler;
							// String rzSj;
							// int jmStatus;
							// String in_Day;
							// String in_Month;
							// String in_Year;
							// String fpmw;
							// String fpid;
							// int i_validDate;
							// WsrzQyUserManageCmdBean curCzyDB;
							System.out.println("[INFO] 普票验证写数据库出现异常:" + nsrsbh
									+ "," + rsj + "(" + ulms + "ms)");
							dispMessage(response, "900", "其它异常", rzSj, czyDm,
									czyPwd);
							return;
						}
						// String sl;
						// double se;
						// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
						// String err_subType;
						// Map map;
						// CmpHandler cmpHandler;
						// java.sql.Date rdDate;
						// String rddate;
						// int i_err_no;
						// int rzjg;
						// int wxyy;
						// String jmjip;
						// JmHandler curJmHandler;
						// String rzSj;
						// int jmStatus;
						// String in_Day;
						// String in_Month;
						// String in_Year;
						// String fpmw;
						// String fpid;
						// int i_validDate;
						// WsrzQyUserManageCmdBean curCzyDB;
						if (WlrzConst.isSupGDZC()) {
							tmpFpDklMxDataBean.setGdzc_bz(gdzc);
						} else {
							tmpFpDklMxDataBean.setGdzc_bz("N");
						}
						save_Code = tmpFpDklMxDataBean.doInsert(conn);

						System.out.println("[INFO] 保存返回结果.." + save_Code);

						ulms = System.currentTimeMillis() - ulms;
						if (save_Code == 1) {
							java.util.Date sj = tmpFpDklMxDataBean.getRz_Sj();

							SimpleDateFormat sdf = new SimpleDateFormat(
									"yyyy-MM-dd HH:mm:ss");
							rzSj = sdf.format(sj);

							String rtn_fpje = Double.toString(jmFpData
									.getFp_je());
							String rtn_fpse = Double.toString(jmFpData
									.getFp_se());
							if (rtn_fpje != null) {
								rzSj = rzSj + " " + rtn_fpje + " " + rtn_fpse
										+ " " + jmFpData.getFp_dm() + " "
										+ jmFpData.getFp_hm();
							}
							if (tmpFpDklMxDataBean.getRz_Jg() == 3) {
								dispMessage(response, "680", "解密成功，属于失控发票",
										rzSj, czyDm, czyPwd);
								return;
							}
							// String rtn_fpse;
							// String rtn_fpje;
							// SimpleDateFormat sdf;
							// java.util.Date sj;
							// String sl;
							// double se;
							// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
							// String err_subType;
							// Map map;
							// CmpHandler cmpHandler;
							// java.sql.Date rdDate;
							// String rddate;
							// int i_err_no;
							// int save_Code;
							// int rzjg;
							// int wxyy;
							// String jmjip;
							// JmHandler curJmHandler;
							// String rzSj;
							// int jmStatus;
							// String in_Day;
							// String in_Month;
							// String in_Year;
							// String fpmw;
							// String fpid;
							// int i_validDate;
							// WsrzQyUserManageCmdBean curCzyDB;
							if (fpzl.equals("YB")) {
								dispMessage(response, "0", "解密成功，比对正确(增值税)",
										rzSj, czyDm, czyPwd);
								System.out.println("[INFO] 认证通过(增值税):" + nsrsbh
										+ "," + tmpFpDklMxDataBean.getFpdm()
										+ "-" + tmpFpDklMxDataBean.getFphm()
										+ "," + rzSj + "(" + ulms + "ms)");
							} else if (fpzl.equals("FJ")) {
								dispMessage(response, "1001", "解密成功，比对正确(废旧)",
										rzSj, czyDm, czyPwd);
								System.out.println("[INFO] 认证通过(废旧):" + nsrsbh
										+ "," + tmpFpDklMxDataBean.getFpdm()
										+ "-" + tmpFpDklMxDataBean.getFphm()
										+ "," + rzSj + "(" + ulms + "ms)");
							} else if (fpzl.equals("P1")) {
								dispMessage(response, "1002", "解密成功，比对正确(普通)",
										rzSj, czyDm, czyPwd);
								System.out.println("[INFO] 认证通过(普通):" + nsrsbh
										+ "," + tmpFpDklMxDataBean.getFpdm()
										+ "-" + tmpFpDklMxDataBean.getFphm()
										+ "," + rzSj + "(" + ulms + "ms)");
							}
							return;
						}
						// String sl;
						// double se;
						// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
						// String err_subType;
						// Map map;
						// CmpHandler cmpHandler;
						// java.sql.Date rdDate;
						// String rddate;
						// int i_err_no;
						// int save_Code;
						// int rzjg;
						// int wxyy;
						// String jmjip;
						// JmHandler curJmHandler;
						// String rzSj;
						// int jmStatus;
						// String in_Day;
						// String in_Month;
						// String in_Year;
						// String fpmw;
						// String fpid;
						// int i_validDate;
						// WsrzQyUserManageCmdBean curCzyDB;
						System.out.println("[INFO] 存库出错(" + save_Code + "): "
								+ nsrsbh + "," + tmpFpDklMxDataBean.getFpdm()
								+ "-" + tmpFpDklMxDataBean.getFphm() + "("
								+ ulms + "ms)");
						if (save_Code == 1) {
							save_Code = 0;
						} else {
							if (save_Code == 2) {
								rzSj = tmpFpDklMxDataBean.getDs_swjg_dm();
								String rtn_fpje = Double.toString(jmFpData
										.getFp_je());
								String rtn_fpse = Double.toString(jmFpData
										.getFp_se());

								rzSj = rzSj + " " + rtn_fpje + " " + rtn_fpse
										+ " " + jmFpData.getFp_dm() + " "
										+ jmFpData.getFp_hm();
								save_Code = -3;
								if (fpzl.equals("YB")) {
									if (security) {
										dispMessage(response, "650",
												"重复认证(增值税发票)", rzSj, czyDm,
												czyPwd);
									} else {
										dispMessage(response, "0",
												"重复认证(增值税发票)", rzSj, czyDm,
												czyPwd);
									}
									System.out.println("[INFO] 重复认证(增值税):"
											+ nsrsbh + ", " + rzSj + "(" + ulms
											+ "ms)");
								} else if (fpzl.equals("FJ")) {
									dispMessage(response, "1100",
											"重复认证(废旧物资发票)", rzSj, czyDm, czyPwd);
									System.out.println("[INFO] 重复认证(废旧):"
											+ nsrsbh + ", " + rzSj + "(" + ulms
											+ "ms)");
								} else if (fpzl.equals("P1")) {
									dispMessage(response, "1200",
											" 重复认证(普通发票)", rzSj, czyDm, czyPwd);
									System.out.println("[INFO] 重复认证(普通):"
											+ nsrsbh + ", " + rzSj + "(" + ulms
											+ "ms)");
								}
								return;
							}
							// String sl;
							// double se;
							// GSRzFpdklMxDataBean tmpFpDklMxDataBean;
							// CmpHandler cmpHandler;
							// java.sql.Date rdDate;
							// String rddate;
							// int i_err_no;
							// int save_Code;
							// int rzjg;
							// /int wxyy;
							// String jmjip;
							// JmHandler curJmHandler;
							// int jmStatus;
							// String in_Day;
							// String in_Month;
							// String in_Year;
							// String fpmw;
							// String fpid;
							// int i_validDate;
							// WsrzQyUserManageCmdBean curCzyDB;
							if (save_Code == 3) {
								save_Code = -1;
							}
						}
					} else {
						java.sql.Date sj = null;
						sj = new java.sql.Date(System.currentTimeMillis());
						SimpleDateFormat sdf = new SimpleDateFormat(
								"yyyy-MM-dd HH:mm:ss");
						String rSj = sdf.format(sj);

						String rtn_fpje = Double.toString(jmFpData.getFp_je());
						String rtn_fpse = Double.toString(jmFpData.getFp_se());
						if (rtn_fpje != null) {
							rSj = rSj + " " + rtn_fpje + " " + rtn_fpse;
						}
						if (err_subType.equals("1")) {
							if (isNewClient) {
								map.put("czyDm", czyDm);
								map.put("czyPwd", czyPwd);

								String retxml = CreateXmlBean.genCmpResult1(
										map, false);
								dispMessage1(response, retxml);
							} else {
								dispMessage(response, "590", "解密成功，但比对不正确",
										rSj, czyDm, czyPwd);
							}
						}
						if (err_subType.equals("2")) {
							if (isNewClient) {
								map.put("czyDm", czyDm);
								map.put("czyPwd", czyPwd);

								String retxml = CreateXmlBean.genCmpResult1(
										map, false);
								dispMessage1(response, retxml);
							} else {
								dispMessage(response, "590", "解密成功，但比对不正确",
										rSj, czyDm, czyPwd);
							}
						}
						System.out.println("[INFO] 认证未通过:" + nsrsbh + ","
								+ inFpData.getFp_dm() + "-"
								+ inFpData.getFp_hm() + "," + rzSj + "(" + ulms
								+ "ms)");

						return;
					}
					// String err_subType;
					// Map map;
					// CmpHandler cmpHandler;
					// java.sql.Date rdDate;
					// String rddate;
					// int i_err_no;
					// int save_Code;
					// int rzjg;
					// int wxyy;
					// String jmjip;
					// JmHandler curJmHandler;
					// String rzSj;
					// int jmStatus;
					// String in_Day;
					// String in_Month;
					// String in_Year;
					// String fpmw;
					// String fpid;
					// int i_validDate;
					// WsrzQyUserManageCmdBean curCzyDB;
					if (save_Code < 0) {
						throw new SQLException("[WARN] save error");
					}
					if ((rzjg == 0) && (save_Code != 0)) {
						System.out.println("[WARN] 700保存数据失败。");
						dispMessage(response, "700", "数据库操作异常，请重新认证！",
								getCurDateTime(), czyDm, czyPwd);
						return;
					}
				case 400:
					// int save_Code;
					// String jmjip;
					// JmHandler curJmHandler;
					// String rzSj;
					// int jmStatus;
					// String in_Day;
					// String in_Month;
					// String in_Year;
					// String fpmw;
					// String fpid;
					// int i_validDate;
					// WsrzQyUserManageCmdBean curCzyDB;
					wxyy = 128;
					rzjg = 5;
					dispMessage(response, "400", "提交的纳税人识别号非法，请重新提交认证！",
							getCurDateTime(), czyDm, czyPwd);
					break;
				case 403:
					System.out.println("[INFO] 当前认证人与发票的购方、销方均无关:" + nsrsbh
							+ "," + inFpData.getFp_dm() + "-"
							+ inFpData.getFp_hm());

					dispMessage(response, "403", "当前认证人与发票的购方、销方均无关，不能进行认证！",
							getCurDateTime(), czyDm, czyPwd);

					break;
				}
				if (((i_err_no >= 1) && (i_err_no <= 255)) || (i_err_no == -1)) {
					wxyy = 128;
					rzjg = 5;
					System.out.println("1-255:save exception info");
					dispMessage(response, String.valueOf(255),
							"提交的密文有误，请重新提交认证！", getCurDateTime(), czyDm, czyPwd);

					System.out.println("[WARN] " + i_err_no + "无法解密：纳税号:"
							+ nsrsbh + ", 操作员:" + czyDm + ", 认证时间:"
							+ getCurDateTime());
					return;
				}
				break;
			case 530:
				// String jmjip;
				// JmHandler curJmHandler;
				// String rzSj;
				// String in_Day;
				// String in_Month;
				// String in_Year;
				// String fpmw;
				// String fpid;
				// int i_validDate;
				// WsrzQyUserManageCmdBean curCzyDB;
				System.out.println("[ERROR] 530没有可用的解密工作站");
				dispMessage(response, "530", "系统忙，请稍候再试...", getCurDateTime(),
						czyDm, czyPwd);
				break;
			case 540:
				System.out.println("[ERROR] 540连接解密工作站失败");
				dispMessage(response, "540", "连接解密工作站失败，请重新提交数据",
						getCurDateTime(), czyDm, czyPwd);
				break;
			case 550:
				System.out.println("[ERROR] 550无法读取返回的解密数据");
				dispMessage(response, "550", "读取数据失败，请重新提交数据",
						getCurDateTime(), czyDm, czyPwd);
				break;
			default:
				System.out.println("[ERROR] " + jmStatus + "未知错误");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			dispMessage(response, "700", "数据库操作异常，请重新认证！", getCurDateTime(),
					czyDm, czyPwd);
			System.out.println("[info] 数据库操作异常 " + e);
			try {
				if ((conn != null) && (!conn.isClosed())) {
					conn.close();
					conn = null;
				}
			} catch (SQLException se) {
				System.out.println(se.getMessage());
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("[ERROR] 其它异常, 纳税号:" + nsrsbh + " 异常 "
					+ e.toString());

			dispMessage(response, "800", "发生其它异常", getCurDateTime(), czyDm,
					czyPwd);
			try {
				if ((conn != null) && (!conn.isClosed())) {
					conn.close();
					conn = null;
				}
			} catch (SQLException se) {
				System.out.println(se.getMessage());
			}
		} finally {
			try {
				if ((conn != null) && (!conn.isClosed())) {
					conn.close();
					conn = null;
				}
			} catch (SQLException se) {
				System.out.println(se.getMessage());
			}
		}
	}

	private GSRzFpdklMxDataBean setRzFpDklMx(InFpDataBean curFpData,
			String swjg_dm, String czydm, String czymc) {
		java.sql.Date curDate = new java.sql.Date(System.currentTimeMillis());
		String strDate = curDate.toString();
		String cYear = strDate.substring(0, 4);
		String cMonth = strDate.substring(5, 7);
		int rzyf = (Integer.parseInt(cYear) - 1900) * 16
				+ Integer.parseInt(cMonth);

		String kpRq = curFpData.getKprq();
		String mYear = kpRq.substring(0, 2);
		String mMonth = kpRq.substring(2, 4);
		String mDay = kpRq.substring(4, 6);
		String curSKpRq = "20" + mYear + "-" + mMonth + "-" + mDay;

		java.sql.Date curKpRq = java.sql.Date.valueOf(curSKpRq);

		GSRzFpdklMxDataBean tmpBean = new GSRzFpdklMxDataBean();
		tmpBean.setRz_Nsrsbh(curFpData.getRz_nsrsbh());
		tmpBean.setFpdm(curFpData.getFp_dm());
		tmpBean.setFphm(curFpData.getFp_hm());
		tmpBean.setSwjg_Dm(swjg_dm);
		tmpBean.setRz_Nsrsbh(curFpData.getRz_nsrsbh());
		tmpBean.setRz_Fs(5);
		tmpBean.setRz_Jg(0);
		tmpBean.setJglb("0");
		tmpBean.setRz_Wxyy(0);
		tmpBean.setRz_Rgjz_Bz("N");

		tmpBean.setRz_Yf(rzyf);
		tmpBean.setJskh("");

		tmpBean.setFp_Kprq(curSKpRq);
		tmpBean.setGf_Nsrsbh(curFpData.getGf_nsrsbh());
		tmpBean.setXf_Nsrsbh(curFpData.getXf_nsrsbh());

		tmpBean.setJe(curFpData.getFp_je());
		tmpBean.setSe(curFpData.getFp_se());
		tmpBean.setSl(Integer.parseInt(curFpData.getFp_sl()));
		if (curFpData.getQd_bz().equals("Y")) {
			tmpBean.setFp_Mw(curFpData.getFpmw().substring(0, 108));
		} else {
			tmpBean.setFp_Mw(curFpData.getFpmw());
		}
		tmpBean.setQd_bz(curFpData.getQd_bz());
		tmpBean.setWpmxs(curFpData.getHzInfoList());

		tmpBean.setIs_Zh(curFpData.getIs_Zh());
		tmpBean.setZhLst(curFpData.getZhLst());

		tmpBean.setCrcsum("");
		tmpBean.setCzy_Dm("server");
		tmpBean.setCzy_Mc(czymc);
		return tmpBean;
	}

	private GSRzFpdklMxDataBean setRzFpDklMx(InFpDataBean curFpData,
			String swjg_dm, String czydm, String czymc, String locaid) {
		java.sql.Date curDate = new java.sql.Date(System.currentTimeMillis());
		String strDate = curDate.toString();
		String cYear = strDate.substring(0, 4);
		String cMonth = strDate.substring(5, 7);
		int rzyf = (Integer.parseInt(cYear) - 1900) * 16
				+ Integer.parseInt(cMonth);

		String kpRq = curFpData.getKprq();
		String mYear = kpRq.substring(0, 2);
		String mMonth = kpRq.substring(2, 4);
		String mDay = kpRq.substring(4, 6);
		String curSKpRq = "20" + mYear + "-" + mMonth + "-" + mDay;

		java.sql.Date curKpRq = java.sql.Date.valueOf(curSKpRq);

		GSRzFpdklMxDataBean tmpBean = new GSRzFpdklMxDataBean();
		tmpBean.setRz_Nsrsbh(curFpData.getRz_nsrsbh());
		tmpBean.setFpdm(curFpData.getFp_dm());
		tmpBean.setFphm(curFpData.getFp_hm());
		tmpBean.setSwjg_Dm(swjg_dm);
		tmpBean.setRz_Nsrsbh(curFpData.getRz_nsrsbh());
		tmpBean.setRz_Fs(5);
		tmpBean.setRz_Jg(0);
		tmpBean.setJglb("0");
		tmpBean.setRz_Wxyy(0);
		tmpBean.setRz_Rgjz_Bz("N");

		tmpBean.setRz_Yf(rzyf);
		tmpBean.setJskh("");

		tmpBean.setFp_Kprq(curSKpRq);
		tmpBean.setGf_Nsrsbh(curFpData.getGf_nsrsbh());
		tmpBean.setXf_Nsrsbh(curFpData.getXf_nsrsbh());

		tmpBean.setJe(curFpData.getFp_je());
		tmpBean.setSe(curFpData.getFp_se());
		tmpBean.setSl(Integer.parseInt(curFpData.getFp_sl()));
		tmpBean.setFp_Mw(curFpData.getFpmw());
		tmpBean.setCrcsum(locaid);
		tmpBean.setCzy_Dm(czydm);
		tmpBean.setCzy_Mc(czymc);

		return tmpBean;
	}

	private List getInHzInfoList(String sh, String gfmc, String xfmc,
			String mxdata) {
		System.out.println("===================" + mxdata);
		int mxcount = 0;
		try {
			mxcount = Integer.parseInt(mxdata.substring(0, 1));
		} catch (Exception E) {
			System.out.println("物品明细数据异常 " + sh + " " + mxdata);
			return new ArrayList();
		}
		String[] mxs = (mxdata.substring(1) + " ").split("¤");
		if (mxcount * 3 != mxs.length) {
			System.out.println("物品明细数据异常 " + sh + " " + mxdata);
			return new ArrayList();
		}
		List rtn = new ArrayList();
		rtn.add(replaceInvlidCharacter(gfmc));
		rtn.add(replaceInvlidCharacter(xfmc));
		rtn.add(mxdata.subSequence(0, 1));
		for (int i = 0; i < mxs.length; i++) {
			rtn.add(replaceInvlidCharacter(mxs[i].trim()));
		}
		return rtn;
	}

	private String replaceInvlidCharacter(String original) {
		String newString = original.replaceAll("\t", "");
		newString = newString.replaceAll("\t", "");
		newString = newString.replaceAll(" ", "");
		newString = newString.replaceAll("　", "");

		return newString;
	}

	private String JMSvr(HttpServletRequest req) {
		String rtn = "";
		String fpmw = req.getParameter("mw");
		fpmw = TransQuotePrintable(fpmw);
		if ((fpmw.length() == 84) || (fpmw.length() == 108)
				|| (fpmw.length() == 780)) {
			JmjBean jb = pool.getJmj();
			jb = pool.getJmj();
			if (jb != null) {
				String jmjip = jb.getJmjIP();
				JmHandler jh = new JmHandler();
				boolean hzfw = "hzfw".equals(req.getParameter("action"));
				if (jb.isServer()) {
					jh.doJmProc_Jms(fpmw, jmjip, hzfw);
				} else {
					jh.doJmProc("", fpmw, "", jmjip, hzfw);
				}
				
				///获取从解密机获取的发票信息，通过发票密文672位获取汉字信息
				JmFpDataBean jmBean = jh.getCurJmData();
				pool.releaseJmj(jb);
				switch (jh.getStatus()) {
				case 0:
					rtn = "0&";
					rtn = rtn + jmBean.getFp_dm() + "\n";
					rtn = rtn + jmBean.getFp_hm() + "\n";
					rtn = rtn + jmBean.getGf_nsrsbh() + "\n";
					rtn = rtn + jmBean.getKprq() + "\n";
					rtn = rtn + jmBean.getFp_je() + "\n";
					rtn = rtn + jmBean.getFp_se() + "\n";
					rtn = rtn + jmBean.getFp_sl() + "\n";
					rtn = rtn + jmBean.getXf_nsrsbh() + "\n";
					break;
				case 530:
					rtn = "";
					break;
				case 540:
					rtn = "";
					break;
				case 550:
					rtn = "";
					break;
				default:
					rtn = "97&";
					break;
				}
			} else {
				rtn = "98&无可用解密机，请重试";
			}
		} else {
			rtn = "99&密文长度有误";
		}
		return rtn;
	}

	public static void main(String[] args) {
		new WlrzJmjControlServletLn().getInHzInfoList("", "", "",
				"2阿萨德飞¤as¤2341¤¤阿萨德飞¤");
	}
}

/*
 * Location: D:\htjs\document\wsrz\WsrzEjbInf\ * Qualified Name:
 * gov.sat.tax.fwsk.wlrz.WlrzJmjControlServletLn * JD-Core Version: 0.7.0.1
 */